<?php


namespace app\middleware;


use app\controller\JWT;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;

class WbAuthCheck implements MiddlewareInterface
{
    public function process(Request $request, callable $next): Response
    {
        if (!$request->header('wb_token')) {
            return redirect('/wb/authorize');
        } else {
            $wb_token = $request->header('wb_token');
            $decode = JWT::decode($wb_token);
            $request->wb_token = $decode->token;
        }
        return $next($request);
    }
}
